#include "stm32f10x.h"   // Device header
uint16_t Countsensor_count;
void COUNTERSENSOR_Init( )
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);  //GPIO口配置
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
	GPIO_InitTypeDef GPIO_Initstructure;
	GPIO_Initstructure.GPIO_Mode =GPIO_Mode_IPU;
	GPIO_Initstructure.GPIO_Pin = GPIO_Pin_14;
	GPIO_Initstructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB,&GPIO_Initstructure);
    
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource14);
	EXTI_InitTypeDef EXTI_InitStruct;
	EXTI_InitStruct.EXTI_Line = EXTI_Line14;  //PB14
	EXTI_InitStruct.EXTI_LineCmd = ENABLE;
	EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;  //中断功能
	EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;   //下降沿触发
	EXTI_Init(&EXTI_InitStruct);
	
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	NVIC_InitTypeDef  NVIC_InitStruct;
	NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;   //中断10~15接口
	NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;   //
	NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级
	NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;   //响应优先级
    NVIC_Init(&NVIC_InitStruct);
	
}


uint16_t Countsensor_returncount( )
{
	return Countsensor_count;
}
void EXTI15_10_IRQHandler( )
{
	if (EXTI_GetITStatus(EXTI_Line14) == SET);
	{
	 if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14) == 1| GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14) == 0 )
	 {
		 Countsensor_count++;
		EXTI_ClearITPendingBit(EXTI_Line14);
		
	 }
	}
}